<?php 
require "DataLoad.php"; 
CheckAdmin2();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title><?php echo $GuildName;?> - DKP系统</title>
<script language="JavaScript" src="inc/jquery.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="Generator" content="EditPlus">
<meta name="Author" content="SULei">
<meta name="Keywords" content="DKP WOW GUILD">
<meta name="Description" content="">
<link href="<?php echo $StylePath;?>/main.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" src="<?php echo $StylePath;?>/styleplus.js"></script>
<style type="text/css" media="all">

</style>
</head>

<body>

<div class="header">
<?php require "menu.php"; ?>
</div>
<div class="main">

<?php 
switch ($_GET["action"]) {
	case "add":
raidplan_addsql("new");
		break;
	case "del":
		if (is_numeric($_GET["id"])) {

raidplan_delsql($_GET["id"]);
		} 

		break;
	case "newplan":
raidplan_add();
		break;
	case "edit":
		if (is_numeric($_GET["id"])) {

raidplan_edit($_GET["id"]);
		} 

		break;
	case "editsql":
raidplan_addsql($_GET["id"]);
		break;
	default:

		print "...";
		break;
} 
?>
	</div>
<?php require "footer.php"; ?>

</body>
</html>
<?php 
function raidplan_add() {

	print "<form action='?action=add' method='post'>";
	print "<table class='outframe interlace'>";
	print "<tr><th colspan='2'><div class='title'><img src='images/icon/note.jpg' >填写活动基本信息</div></th></tr>";
	print "<tr><td>活动主题*</td><td><input type='input' name='raid_name' value='' size='35'/></td></tr>";
	print "<tr><td>DKP分类*</td><td>".formselect("raid_class","id","class_name"," ")."</td></tr>";
	print "<tr><td>集合时间*</td><td><input type='input' name='raid_concentratetime' size='28' value=''/> 格式: ".strftime("%m/%d/%Y %H:%M:%S %p")."</td></tr>";
	print "<tr><td>行动时间*</td><td><input type='input' name='raid_actiontime' size='28' value=''/></td></tr>";
	print "<tr><td>结束时间*</td><td><input type='input' name='raid_endtime' size='28' value=''/></td></tr>";
	print "<tr><td>人数要求*</td><td><input type='input' name='raid_personnel' value=''/> 可以填写副本的最大人数</td></tr>";
	//print "<tr><td>DKP规则*</td><td>".formselect("ruler","id","ruler_name"," ")."</td></tr>";
	print "<tr><td>指 挥 官</td><td><input type='input' name='raid_commander' value=''/></td></tr>";
	print "<tr><td>备 注</td><td><textarea name='raid_plan' rows='8' cols='50'></textarea></td></tr>";
	print "<tr><td></td><td><input type='submit' value='确定'/></td></tr>";
	print "</table>";
	print "</form>";
	return $function_ret;
} 

function raidplan_edit($id) {
	$sql="select * from raid where id=".$id;
	if ($result = mysql_query($sql)) {
		$row = mysql_fetch_array($result);
		print "<form action='?action=editsql' method='post'>";
		print "<table class='outframe interlace'>";
		print "<tr><th colspan='2'><div class='title'><img src='images/icon/note.jpg' >修改活动基本信息</div></th></tr>";
		print "<tr><td>活动主题*</td><td><input type='input' name='raid_name' value='".$row["raid_name"]."' size='35'/></td></tr>";
		print "<tr><td>DKP分类*</td><td>".formselect("raid_class","id","class_name",$row["raid_class"])."</td></tr>";
		print "<tr><td>集合时间*</td><td><input type='input' name='raid_concentratetime' size='28' value='".$row["raid_concentratetime"]."'/> 格式: 2005-09-28 19:30:00</td></tr>";
		print "<tr><td>行动时间*</td><td><input type='input' name='raid_actiontime' size='28' value='".$row["raid_actiontime"]."'/></td></tr>";
		print "<tr><td>结束时间*</td><td><input type='input' name='raid_endtime' size='28' value='".$row["raid_endtime"]."'/></td></tr>";
		print "<tr><td>人数要求*</td><td><input type='input' name='raid_personnel' value='".$row["raid_personnel"]."'/></td></tr>";
		//print "<tr><td>DKP规则*</td><td>".formselect("ruler","id","ruler_name",$result["raid_ruler"])."</td></tr>";
		print "<tr><td>指 挥 官</td><td><input type='input' name='raid_commander' value='".$row["raid_commander"]."'/></td></tr>";
		print "<tr><td>详细计划</td><td><textarea name='raid_plan' rows='8' cols='50'>".$row["raid_plan"]."</textarea></td></tr>";
		print "<tr><td></td><td><input type='submit' value='确定'/><input type='hidden' name='id' value='".$row["id"]."' size='35'/></td></tr>";
		print "</table>";
		print "</form>";
		return true;
	}else{
		echo "指定活动未找到 $sql";
		return false;
	}
} 

function raidplan_addsql($s) {

//添加新的分类
//验证提交数据有效性
//数据库字段:
	if (${"raid_name"}=="") {
		$errorinfo=$errorinfo."<li>活动名称请不要留空.</li>";
	} 
	if (${"raid_concentratetime"}=="" || ${"raid_actiontime"}=="" || ${"raid_endtime"}=="") {

		$errorinfo=$errorinfo."<li>活动的各个时间项不能为空.</li>";
	}
		else
	{

		if ($Datediff["m"][${"raid_actiontime"}][${"raid_endtime"}]<0) {
			$errorinfo=$errorinfo."<li>结束时间不能在开始时间之前</li>";
		} 
	} 

	if (${"raid_name"}=="") {
		$errorinfo=$errorinfo."<li>活动名称请不要留空.</li>";
	} 
	if (!$IsDate[${"raid_concentratetime"}]) {
		$errorinfo=$errorinfo."<li>集结的时间格式不正确,请参考旁边的格式</li>";
	} 
	if (!$IsDate[${"raid_actiontime"}]) {
		$errorinfo=$errorinfo."<li>行动的时间格式不正确,请参考旁边的格式</li>";
	} 
	if (!$IsDate[${"raid_endtime"}]) {
		$errorinfo=$errorinfo."<li>结束时间格式不正确,请参考旁边的格式</li>";
	} 
	if (!is_numeric(${"raid_personnel"})) {
		$errorinfo=$errorinfo."<li>人员数量必须为数字</li>";
	} 
	if (${"ruler_name"}=="") {
		$errorinfo=$errorinfo."<li>请选择一个DKP规则,如果没有请先建立.</li>";
	} 
//if IsValidEmail(request("L_AuthorMail"))<>"true" and request("L_AuthorMail")<>"" then errorinfo=errorinfo & "<li>无效的邮箱地址.</li>"
//验证///

	if ($errorinfo!="") {

//抛出错误提示
		print "<p>表单信息有误,提示如下:</p><ul>".$errorinfo."</ul>";
		print "请<a href='".$Url."'>返回</a>重新修改.";
	}
		else
	{

//写入数据库
		if (is_numeric($s)) {

			$sql="Select * from raid where id=".$s;
			$result = mysql_query($sql);
			if ($result->bof || $result->eof) {
				return $function_ret;

			} 
		}
			else
		{

			$sql="Select * from raid where (id is null)";
			$result = mysql_query($sql);
			$result->addnew;
			$result["raid_player"]="";
		} 

		$result["raid_name"]=trim(${"raid_name"});
		$result["raid_class"]=trim(${"class_name"});
		$result["raid_concentratetime"]=trim(${"raid_concentratetime"});
		$result["raid_actiontime"]=${"raid_actiontime"};
		$result["raid_endtime"]=${"raid_endtime"};
		$result["raid_personnel"]=${"raid_personnel"};
		$result["raid_ruler"]=${"ruler_name"};
		$result["raid_commander"]=trim(${"raid_commander"});
		$result["raid_plan"]=${"raid_plan"};
		$result->update;
		$result->close;
		if (is_numeric($s)) {

showmessage("修改完成 <a href='".$Url."'>继续修改</a> | <a href='admin_report.php'>查看列表</a> | <a href='raid_report.php?id=".$s."'>查看该活动报告</a>");
		}
			else
		{

			$sql="select id from raid where raid_endtime=#".${"raid_endtime"}."# order by id desc";
			$result = mysql_query($sql);
showmessage("继续为活动<a href='/fsdkp/admin_report.php?action=collect&id=".$result["id"]."'>添加成员</a>");
			$result->close;
		} 

	} 

	return $function_ret;
} 


function raidplan_delsql($id) {
	$sql="Delete from raid where id=".$id;
	mysql_query($sql);
	print "删除活动记录...<br>";
	$sql="Delete from dkplist where Raidid=".$id;
	mysql_query($sql);
	print "删除活动DKP缓存...<br>";
	$sql="Delete from raid_event where event_raidid=".$id;
	mysql_query($sql);
	print "删除活动事件....<br>";
	$sql="Delete from gbook where gbook_raidid='".($id)."'";
	mysql_query($sql);
	print "删除活动留言....<br>";
	print "ALL DONE.<br>";
	return $function_ret;
} 



?>
